<template>
  <div class="edit">
    <el-dialog :visible.sync="dialogVisible" center class="countDialog" :close-on-click-modal="false" @close="resetO('ruleForm')">
      <div slot="title" class="dialog-title">{{ pageTitle }}</div>
      <div>
        <el-form ref="ruleForm" :rules="rules" :model="form" size="medium" label-width="100px">
          <el-form-item prop="budget" label="金额(元)">
            <el-input-number size="mini" v-model="form.budget" min="0" precision="2" step="0.01" max="100000" placeholder="请输入金额(元)"></el-input-number>
          </el-form-item>
          <el-form-item>
            <el-button size="small" type="primary" @click="onSubmit('ruleForm')">提交</el-button>
            <el-button size="small" @click="resetO('ruleForm')">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {dsp_adv_edit_budget} from '@/api/dsp_advertiser'
export default {
  name: 'dsp_adv-edit_budget',
  data(){
    return {
      dialogVisible: false,
      pageTitle:'新增',
      form:{
        media_id:''
      },
      rules:{
        name:[
          {required: true, message: '请输入名称', trigger: 'blur'}
        ]
      }
    }
  },
  computed: {
  },
  components: {

  },
  mounted(){
  },
  created() {
  },
  methods: {
    resetO(formName){
      this.dialogVisible = false
      this.form = {}
      this.$refs[formName].resetFields()
      //调用父组件方法
      this.$parent.GetList()
    },
    onSubmit(formName){
      var sdata = this.form
      sdata.flag = parseInt(sdata.flag)
      sdata.budget = parseFloat(sdata.budget)
      console.log(sdata)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          dsp_adv_edit_budget(sdata).then(res => {
            var data = res.data
            console.log(data)
            this.$message({
              showClose: true,
              center:true,
              message: '操作成功',
              type: 'success'
            })
            this.dialogVisible = false
            this.$parent.GetList()
          }).catch(err => {
            console.log(err)
          })
        }else {
          return false
        }
      })

    },
    showInfo(tinfo){
      var info = tinfo
      this.dialogVisible = true
      if (info.id != undefined) {
        this.pageTitle = '编辑'
      }
      this.form = info
    }
  }
}
</script>
<style lang="scss" scoped>
.edit {

}
</style>